const uploadExcelDao = require('../dao/uploadExcelDao');

const uploadExcelService = {
    // 查询某个用户的所有上传文件
    async getAllFiles() {
        let result;
        try {
            let data = await uploadExcelDao.getAllFiles();
            result = { success: true, msg: '获取成功', data };
        } catch (err) {
            result = { success: false, msg: '获取失败' };
        }
        return result;
    },
    // 上传 excel
    async uploadExcel(fileName, data) {
        let result;
        try {
            result = await uploadExcelDao.uploadExcel(fileName, data);
            result = { success: true, msg: '导入成功' };
        } catch (err) {
            result = { success: false, msg: err };
        }
        return result;
    },
    // 下载 excel
    async downloadExcel(id) {
        let result;
        try {
            result = await uploadExcelDao.downloadExcel(id);
            result = { success: true, msg: '下载成功', data: result };
        } catch (err) {
            result = { success: false, msg: '下载失败' };
        }
        return result;
    },
    // 加载二级事项
    async loadSubItem(contentId) {
        let result;
        try {
            result = await uploadExcelDao.loadSubItem(contentId);
            result = { success: true, msg: '下载成功', data: result };
        } catch (err) {
            result = { success: false, msg: '下载失败' };
        }
        return result;
    }
};

module.exports = uploadExcelService;



